
$('#info_modify').click(function(){
	var id = $('#investorId').val();
	window.location.href = ctx +"/investor/edit/"+id;
    return;
});

$('#btn_confirm_allot_employee').click(function(){
	var employeeId = $('#employeeId').val();
	var employeeName = $('#employeeName').html();
	var investorId = $('#investorId').val();
	if (employeeId == null || employeeId == '') {
		bootbox.alert("请选择理财师！");
		return;
	}
	json = "{\"employeeId\":\""+employeeId+"\",\"investorId\":\""+investorId+"\",\"employeeName\":\""+employeeName+"\"}";
	$.ajax({
    	type:"post",
        contentType:"application/json; charset=UTF-8",
        url: ctx + "/investor/allotEmp",
        data:json,
        dataType:"json",
        success: function(msg){
        	$.teninedialog({
                title:'系统提示',
                content:msg.message,
                showCloseButton:false,
                otherButtons:["确定"],
                otherButtonStyles:['btn-primary'],
                bootstrapModalOption:{keyboard: true},
                clickButton:function(sender,modal,index){
                	location.reload();
                }
            });
        },
        error: function (msg) {
        	bootbox.alert("服务器偷了个小懒,分配理财师失败了!");
        }
    });
});

$('#btn_add_relation').click(function(){
	var investorId = $('#investorId').val();
	var content = $('#rela_content').val();
	if(content.length == 0 || content == ''){
		bootbox.alert('联系内容不能为空！');
		return;
	}
	if(content.length > 1024){
		bootbox.alert('联系内容长度不能超过1024字符！');
		return;
	}
	var json = "{\"investorId\":\""+investorId+"\",\"content\":\""+content+"\"}";
	$.ajax({
    	type:"post",
        contentType:"application/json; charset=UTF-8",
        url: ctx + "/investor/addRela",
        data:json,
        dataType:"json",
        success: function(msg){
        	$('#dsimiss_add_relation').click();
        	$('#rela_content').val('');
        	bootbox.alert(msg.message);
        },
        error: function (msg) {
        	bootbox.alert("服务器偷了个小懒,新增联系记录失败了!");
        }
    });
});

//Autocomplete
$("#tags").autocomplete({
    source: function(query,process){
        $.post(ctx + "/investor/employee/"+query.term,{"matchCount":200},function(data){
        	var ebean = []
        	for (var int = 0; int < data.length; int++) {
        		var temp = [];
        		temp.label = data[int].employeeName +"  "+ data[int].employeeNo;
        		temp.value = data[int].employeeNo;
        		temp.id = data[int].employeeId;
        		temp.name = data[int].employeeName;
        		ebean.push(temp);
    		}
            return process(ebean);
        });
    },
    search:function(event, ui){
    	$("#employeeName").html('');
        $("#employeeNo").html('');
        $("#employeeId").val('');
    },
    select: function(event, ui) {
        $("#tags").val(ui.item.label);
        $("#employeeName").html(ui.item.name);
        $("#employeeNo").html(ui.item.value);
        $("#employeeId").val(ui.item.id);
        var uistr =ui.item;
        // 阻止事件的默认行为
        event.preventDefault(); 
    }
});

$("#btn_deal_emp_new").click(function(){
	var employeeId = $('#employeeId').val();
	var employeeName = $('#employeeName').html();
	var investorId = $('#investorId').val();
	if (employeeId == null || employeeId == '') {
		bootbox.alert("请选择理财师！");
		return;
	}
	json = "{\"employeeId\":\""+employeeId+"\",\"investorId\":\""+investorId+"\",\"employeeName\":\""+employeeName+"\"}";
	$.ajax({
    	type:"post",
        contentType:"application/json; charset=UTF-8",
        url: ctx + "/investor/allotEmp",
        data:json,
        dataType:"json",
        success: function(msg){
        	$("#deal_emp_miss").click();
        	$.teninedialog({
                title:'系统提示',
                content:msg.message,
                showCloseButton:false,
                otherButtons:["确定"],
                otherButtonStyles:['btn-primary'],
                bootstrapModalOption:{keyboard: true},
                clickButton:function(sender,modal,index){
                	location.reload();
                }
            });
        },
        error: function (msg) {
        	bootbox.alert("服务器偷了个小懒,分配理财师失败了!");
        }
    });
});

$('#btn_show_modal').click(function(){
	$('#rela_content').val('');
});
